package questionsObjects;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xpk
 * Date: 11/30/13
 * Time: 3:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class QuestionHistory {
    private List<Integer> listOfIndexes;
    private List<Boolean> listOfRights;

    public QuestionHistory() {
        this.listOfIndexes = new ArrayList<Integer>();
        this.listOfRights = new ArrayList<Boolean>();
    }

    public void pushValues(int index, boolean isRight) {
        listOfIndexes.add(index);
        listOfRights.add(isRight);
    }

    public String getIndexes() {
        return listOfIndexes.toString();
    }

    public String getRights() {
        return listOfRights.toString();
    }

    public int getSizeOfHistory() {
        return listOfIndexes.size();
    }

    public int countAnswers(int position, boolean typeOfRight) {
        int counterOfTypes = 0;

        if(position < listOfRights.size()) {
            Iterator<Boolean> iterator = listOfRights.listIterator(position);
            while(iterator.hasNext()) {
                if(iterator.next() == typeOfRight) {
                    ++counterOfTypes;
                }
            }
        }
        return counterOfTypes;
    }

    public boolean haveDuplicatesInHistory(int index) {
        for(Integer s : listOfIndexes) {
            if(s == index) {
                return true;
            }
        }
        return false;
    }
}
